/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.jake.nb.ext.ant.hints.ui;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import javax.swing.JComponent;
import org.netbeans.spi.options.OptionsPanelController;
import org.openide.util.HelpCtx;
import org.openide.util.Lookup;

//@OptionsPanelController.SubRegistration(location = "Editor",
//displayName = "#AdvancedOption_DisplayName_Ant",
//keywords = "#AdvancedOption_Keywords_Ant",
//keywordsCategory = "Editor/Ant")
public final class AntOptionsPanelController extends OptionsPanelController {

  private AntPanel panel;
  private final PropertyChangeSupport pcs = new PropertyChangeSupport(this);
  private boolean changed;

  @Override
  public void update() {
    if (panel != null) {
      panel.update();
    }
  }

  @Override
  public void applyChanges() {
    if (isChanged()) {
      panel.applyChanges();
    }
  }

  @Override
  public void cancel() {
    if (panel != null) {
      panel.cancel();
    }
  }

  @Override
  public boolean isValid() {
    return true;
  }

  @Override
  public boolean isChanged() {
    return panel == null ? false : panel.isChanged();
  }

  @Override
  public HelpCtx getHelpCtx() {
    return new HelpCtx("netbeans.optionsDialog.pom.hints");
  }

  @Override
  public synchronized JComponent getComponent(Lookup masterLookup) {
    if (panel == null) {
      panel = new AntPanel();
    }
    return panel;
  }

  @Override
  public void addPropertyChangeListener(PropertyChangeListener l) {
    pcs.addPropertyChangeListener(l);
  }

  @Override
  public void removePropertyChangeListener(PropertyChangeListener l) {
    pcs.removePropertyChangeListener(l);
  }

  void changed() {
    if (!changed) {
      changed = true;
      pcs.firePropertyChange(OptionsPanelController.PROP_CHANGED, false, true);
    }
    pcs.firePropertyChange(OptionsPanelController.PROP_VALID, null, null);
  }
}
